home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / binutils.252 / gas / config / obj-som.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-13  |  6.8 KB  |  250 lines

  1. /* SOM object file format.
  2.    Copyright (C) 1993 Free Software Foundation, Inc.
  3.  
  4.    This file is part of GAS, the GNU Assembler.
  5.  
  6.    GAS is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as
  8.    published by the Free Software Foundation; either version 2,
  9.    or (at your option) any later version.
  10.  
  11.    GAS is distributed in the hope that it will be useful, but
  12.    WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
  14.    the GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public
  17.    License along with GAS; see the file COPYING.  If not, write
  18.    to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.    Written by the Center for Software Science at the University of Utah
  21.    and by Cygnus Support.  */
  22.  
  23. #include "as.h"
  24. #include "subsegs.h"
  25. #include "aout/stab_gnu.h"
  26. #include "obstack.h"
  27.  
  28. /* SOM does not need any pseudo-ops.  */
  29.  
  30. const pseudo_typeS obj_pseudo_table[] =
  31. {
  32.   {NULL}
  33. };
  34.  
  35. static int version_seen = 0;
  36. static int copyright_seen = 0;
  37.  
  38. /* Unused by SOM.  */
  39. void obj_read_begin_hook () {}
  40.  
  41. /* Handle a .version directive.  */
  42.  
  43. void
  44. obj_som_version (unused)
  45.      int unused;
  46. {
  47.   char *version, c;
  48.  
  49.   if (version_seen)
  50.     {
  51.       as_bad ("Only one .version pseudo-op per file!");
  52.       ignore_rest_of_line ();
  53.       return;
  54.     }
  55.  
  56.   SKIP_WHITESPACE ();
  57.   if (*input_line_pointer == '\"')
  58.     {
  59.       version = input_line_pointer;
  60.       ++input_line_pointer;
  61.       while (is_a_char (next_char_of_string ()))
  62.     ;
  63.       c = *input_line_pointer;
  64.       *input_line_pointer = '\000';
  65.     }
  66.   else
  67.     {
  68.       as_bad ("Expected quoted string");
  69.       ignore_rest_of_line ();
  70.       return;
  71.     }
  72.  
  73.   version_seen = 1;
  74.   if (bfd_som_attach_aux_hdr (stdoutput, VERSION_AUX_ID, version) == false)
  75.     {
  76.       bfd_perror (stdoutput->filename);
  77.       as_perror ("FATAL: Attaching version header %s", stdoutput->filename);
  78.       exit (EXIT_FAILURE);
  79.     }
  80.   *input_line_pointer = c;
  81.   demand_empty_rest_of_line ();
  82. }
  83.  
  84. /* Handle a .copyright directive.   This probably isn't complete, but
  85.    it's of dubious value anyway and (IMHO) not worth the time to finish.
  86.    If you care about copyright strings that much, you fix it.  */
  87.  
  88. void
  89. obj_som_copyright (unused)
  90.      int unused;
  91. {
  92.   char *copyright, c;
  93.  
  94.   if (copyright_seen)
  95.     {
  96.       as_bad ("Only one .copyright pseudo-op per file!");
  97.       ignore_rest_of_line ();
  98.       return;
  99.     }
  100.  
  101.   SKIP_WHITESPACE ();
  102.   if (*input_line_pointer == '\"')
  103.     {
  104.       copyright = input_line_pointer;
  105.       ++input_line_pointer;
  106.       while (is_a_char (next_char_of_string ()))
  107.     ;
  108.       c = *input_line_pointer;
  109.       *input_line_pointer = '\000';
  110.     }
  111.   else
  112.     {
  113.       as_bad ("Expected quoted string");
  114.       ignore_rest_of_line ();
  115.       return;
  116.     }
  117.  
  118.   copyright_seen = 1;
  119.   if (bfd_som_attach_aux_hdr (stdoutput, COPYRIGHT_AUX_ID, copyright) == false)
  120.     {
  121.       bfd_perror (stdoutput->filename);
  122.       as_perror ("FATAL: Attaching copyright header %s", stdoutput->filename);
  123.       exit (EXIT_FAILURE);
  124.     }
  125.   *input_line_pointer = c;
  126.   demand_empty_rest_of_line ();
  127. }
  128.  
  129. /* Perform any initialization necessary for stabs support.
  130.  
  131.    For SOM we need to create the space which will contain the
  132.    two stabs subspaces.  Additionally we need to set up the
  133.    space/subspace relationships and set space/subspace attributes
  134.    which BFD does not understand.  */
  135.  
  136. void
  137. obj_som_init_stab_section (seg)
  138.      segT seg;
  139. {
  140.   segT saved_seg = now_seg;
  141.   segT space;
  142.   subsegT saved_subseg = now_subseg;
  143.   char *p, *file;
  144.   unsigned int stroff;
  145.  
  146.   /* Make the space which will contain the debug subspaces.  */
  147.   space = bfd_make_section_old_way (stdoutput, "$GDB_DEBUG$");
  148.  
  149.   /* Set SOM specific attributes for the space.  In particular we set
  150.      the space "defined", "private", "sort_key", and "spnum" values. 
  151.  
  152.      Due to a bug in pxdb (called by hpux linker), the sort keys
  153.      of the various stabs spaces/subspaces need to be "small".  We
  154.      reserve range 72/73 which appear to work well.  */
  155.   obj_set_section_attributes (space, 1, 1, 72, 2);
  156.   bfd_set_section_alignment (stdoutput, space, 2);
  157.  
  158.   /* Set the containing space for both stab sections to be $GDB_DEBUG$
  159.      (just created above).  Also set some attributes which BFD does
  160.      not understand.  In particular, access bits, sort keys, and load
  161.      quadrant.  */
  162.   obj_set_subsection_attributes (seg, space, 0x1f, 73, 0);
  163.   bfd_set_section_alignment (stdoutput, seg, 2);
  164.  
  165.   /* Make some space for the first special stab entry and zero the memory.
  166.      It contains information about the length of this file's
  167.      stab string and the like.  Using it avoids the need to 
  168.      relocate the stab strings.
  169.  
  170.      The $GDB_STRINGS$ space will be created as a side effect of
  171.      the call to get_stab_string_offset.  */
  172.   p = frag_more (12);
  173.   memset (p, 0, 12);
  174.   as_where (&file, (unsigned int *) NULL);
  175.   stroff = get_stab_string_offset (file, "$GDB_STRINGS$");
  176.   know (stroff == 1);
  177.   md_number_to_chars (p, stroff, 4);
  178.   seg_info (seg)->stabu.p = p;
  179.  
  180.   /* Set the containing space for both stab sections to be $GDB_DEBUG$
  181.      (just created above).  Also set some attributes which BFD does
  182.      not understand.  In particular, access bits, sort keys, and load
  183.      quadrant.  */
  184.   seg = bfd_get_section_by_name (stdoutput, "$GDB_STRINGS$");
  185.   obj_set_subsection_attributes (seg, space, 0x1f, 72, 0);
  186.   bfd_set_section_alignment (stdoutput, seg, 2);
  187.  
  188.   subseg_set (saved_seg, saved_subseg);
  189. }
  190.  
  191. /* Fill in the counts in the first entry in a .stabs section.  */
  192.  
  193. static void
  194. adjust_stab_sections (abfd, sec, xxx)
  195.      bfd *abfd;
  196.      asection *sec;
  197.      PTR xxx;
  198. {
  199.   asection *strsec;
  200.   char *p;
  201.   int strsz, nsyms;
  202.  
  203.   if (strcmp ("$GDB_SYMBOLS$", sec->name))
  204.     return;
  205.  
  206.   strsec = bfd_get_section_by_name (abfd, "$GDB_STRINGS$");
  207.   if (strsec)
  208.     strsz = bfd_section_size (abfd, strsec);
  209.   else
  210.     strsz = 0;
  211.   nsyms = bfd_section_size (abfd, sec) / 12 - 1;
  212.  
  213.   p = seg_info (sec)->stabu.p;
  214.   assert (p != 0);
  215.  
  216.   bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6);
  217.   bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8);
  218. }
  219.  
  220. #if 0
  221. /* Adjust the VMA address for each $CODE$ subspace.  */
  222. static void
  223. adjust_code_sections (abfd, sec, xxx)
  224.      bfd *abfd;
  225.      asection *sec;
  226.      PTR xxx;
  227. {
  228.   static unsigned size_so_far = 0;
  229.  
  230.   if (strcmp (sec->name, "$CODE$"))
  231.     return;
  232.  
  233.   bfd_set_section_vma (stdoutput, sec, size_so_far);
  234.   size_so_far += bfd_get_section_size_before_reloc (sec);
  235. }
  236. #endif
  237.  
  238. /* Called late in the asssembly phase to adjust the special
  239.    stab entry and to set the starting address for each code subspace.  */
  240.  
  241. void
  242. som_frob_file ()
  243. {
  244.   bfd_map_over_sections (stdoutput, adjust_stab_sections, (PTR) 0);
  245. #if 0
  246.   See comment in tc-hppa.c:pa_proc about GDB lossage
  247.   bfd_map_over_sections (stdoutput, adjust_code_sections, (PTR) 0);
  248. #endif
  249. }
  250.